// pages/index/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imglist:["/assets/images/qs1.GIF","/assets/images/qs2.GIF","/assets/images/qs3.GIF","/assets/images/qs4.GIF",],
    runname:["呼啦圈","举重","跳绳","哑铃"],
    index:0,
    count:8,
    total:8,
    timer:null
  },
changeTimer:function(){
  var that = this
  if(this.data.index == this.data.imglist.length){
    wx.showModal({
      title:'提示',
      content:'运动完成',
      confirmText:'休息一下',
      cancelText:'继续运动',
      success:function(res){
        if(res.confirm){
          clearTimeout(that.data.timer)
          that.setData({
            index:0,
            count:that.data.total
          })
          wx.navigateTo({
            url: '/pages/first/first',
          })
        }else if(res.cancel){
          that.setData({
            index:0
          },function(){
            that.changeTimer()
          })
        }
      }
    })
  }else{
    this.data.timer = setTimeout(()=>{
      this.setData({
        count:this.data.count-1
      })
      if(this.data.count<=0){
        this.setData({
          index:this.data.index+1,
          count:that.data.total
        })
        this.changeTimer()
      }else{
        this.changeTimer()
      }
    },1000)
  }
},
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    var that = this;
    this.setData({
      count:that.data.total
    })
    this.changeTimer()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {
    clearTimeout(this.data.timer)
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {
    clearTimeout(this.data.timer)
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})